package com.byb.server.service.impl;

import com.byb.server.service.ClaimScoringService;
import com.byb.server.domain.ClaimScoring;
import com.byb.server.repository.ClaimScoringRepository;
import com.byb.server.repository.search.ClaimScoringSearchRepository;
import com.byb.server.service.dto.ClaimScoringDTO;
import com.byb.server.service.mapper.ClaimScoringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import static org.elasticsearch.index.query.QueryBuilders.*;

/**
 * Service Implementation for managing ClaimScoring.
 */
@Service
@Transactional
public class ClaimScoringServiceImpl implements ClaimScoringService{

    private final Logger log = LoggerFactory.getLogger(ClaimScoringServiceImpl.class);

    private final ClaimScoringRepository claimScoringRepository;

    private final ClaimScoringMapper claimScoringMapper;

    private final ClaimScoringSearchRepository claimScoringSearchRepository;
    public ClaimScoringServiceImpl(ClaimScoringRepository claimScoringRepository, ClaimScoringMapper claimScoringMapper, ClaimScoringSearchRepository claimScoringSearchRepository) {
        this.claimScoringRepository = claimScoringRepository;
        this.claimScoringMapper = claimScoringMapper;
        this.claimScoringSearchRepository = claimScoringSearchRepository;
    }

    /**
     * Save a claimScoring.
     *
     * @param claimScoringDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public ClaimScoringDTO save(ClaimScoringDTO claimScoringDTO) {
        log.debug("Request to save ClaimScoring : {}", claimScoringDTO);
        ClaimScoring claimScoring = claimScoringMapper.toEntity(claimScoringDTO);
        claimScoring = claimScoringRepository.save(claimScoring);
        ClaimScoringDTO result = claimScoringMapper.toDto(claimScoring);
       // claimScoringSearchRepository.save(claimScoring);
        return result;
    }

    /**
     *  Get all the claimScorings.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<ClaimScoringDTO> findAll(Pageable pageable) {
        log.debug("Request to get all ClaimScorings");
        return claimScoringRepository.findAll(pageable)
            .map(claimScoringMapper::toDto);
    }

    /**
     *  Get one claimScoring by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public ClaimScoringDTO findOne(Long id) {
        log.debug("Request to get ClaimScoring : {}", id);
        ClaimScoring claimScoring = claimScoringRepository.findOne(id);
        return claimScoringMapper.toDto(claimScoring);
    }

    /**
     *  Delete the  claimScoring by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete ClaimScoring : {}", id);
        claimScoringRepository.delete(id);
        //claimScoringSearchRepository.delete(id);
    }

    /**
     * Search for the claimScoring corresponding to the query.
     *
     *  @param query the query of the search
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<ClaimScoringDTO> search(String query, Pageable pageable) {
        log.debug("Request to search for a page of ClaimScorings for query {}", query);
        Page<ClaimScoring> result = claimScoringSearchRepository.search(queryStringQuery(query), pageable);
        return result.map(claimScoringMapper::toDto);
    }
}
